Add X-Accel-Buffering: no header to SSE responses#848
Open
rameshreddy-adutla wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
Add X-Accel-Buffering: no header to SSE responses#848rameshreddy-adutla wants to merge 1 commit intomodelcontextprotocol:mainfrom
rameshreddy-adutla wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
Proxy servers like Nginx buffer responses by default, which causes SSE streams to be delayed. Adding the X-Accel-Buffering: no header instructs reverse proxies to disable response buffering for SSE endpoints, ensuring real-time streaming delivery. Applied to all three SSE response locations: - HttpServletSseServerTransportProvider (SSE endpoint) - HttpServletStreamableServerTransportProvider (GET and POST SSE) Fixes modelcontextprotocol#293 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the
X-Accel-Buffering: noheader to all SSE response endpoints to prevent reverse proxy buffering.Problem
Proxy servers like Nginx buffer HTTP responses by default. For SSE (Server-Sent Events) endpoints, this causes events to be held in the buffer and delivered in batches instead of being streamed in real-time. This is particularly problematic for MCP transports that rely on SSE for real-time communication.
Fix
Added
response.setHeader("X-Accel-Buffering", "no")to all three SSE response locations:HttpServletSseServerTransportProvider— SSE endpoint handlerHttpServletStreamableServerTransportProvider— GET handler (SSE stream)HttpServletStreamableServerTransportProvider— POST handler (streaming requests)This header is a de facto standard supported by Nginx, AWS ALB, and other common proxies. It has no effect when no proxy is present.
Testing
All 680 existing tests pass (1 pre-existing Docker container startup failure unrelated to this change).
Fixes #293